

<body>

<div class="warp">
    <!--header-->
    <header class="hd">
        <a href="javascript:history.go(-1)" class="l-icon only-icon">
            <i class="iconfont icon-left1"></i>
        </a>

        <p class="tit2">
            注册
        </p> 
    </header>

    <div class="register-form">
        <div class="input-bar">
                <span>
                    <i class="iconfont icon-shouji"></i>
                </span>
            <input type="text" placeholder="请输入手机号码" id="mobile">
        </div>
        <div class="verifica-bar">
                <span>
                    <i class="iconfont icon-anquan"></i>
                </span>
            <input type="text" placeholder="请输入验证码" id="captcha">

            <a class="sendmsg send-standby" id="send-captcha" >
                发送验证码
            </a>
        </div>
        <div class="input-bar">
                <span>
                    <i class="iconfont icon-suo"></i>
                </span>
            <input type="password" placeholder="请输入6-12位密码" id="password1">
        </div>
        <div class="input-bar">
                <span>
                    <i class="iconfont icon-suo"></i>
                </span>
            <input type="password" placeholder="再次输入密码" id="password2">
        </div>
        <p class="clause">
            <a href="#123">《使用条款和用户协议》</a>
        </p>
        <a class="register-btn" id="submit">
            注册并登陆
        </a>

        <p  class="gologin">
            <a href="/home/account/login">已有账号直接登录</a>
        </p>
    </div>



</div>

<script src="<?php echo $base_url;?>/static/dist/js/base.js"></script>

<script>
    //验证码倒计时
    var iTimer = 0;
    // 矫正rem
    function correctrem() {
        var rem_full_width = $("<div id='rem-test' style='width:7.5rem'></div>").appendTo($('body')).width();
        var device_width = Math.min(document.documentElement.clientWidth, 640);
        if (rem_full_width !== device_width) {
            document.documentElement.style.fontSize = (device_width / 7.5) * (device_width / rem_full_width) + 'px';
        }
        $('#rem-test').remove();
    }
    correctrem();


    $(function () {
        //发送验证码
        $('#send-captcha').on("click",function() {
            var mobile = $('#mobile').val();
            var pattern = /^1[34578]\d{9}$/;
            console.log($(this).hasClass("send-standby"))
            if (!pattern.test(mobile)) {
                alert("请填写11位数字的正确号码");
                return;
            }
            if (!navigator.onLine) {
                alert("网络连接异常，请检查网络");
                return;
            }
            var self = this;
            if ($(this).hasClass("send-standby")) {
                // console.log('cc');
                $.getJSON("/home/account/sms_port?phone=" + mobile + "&type=0", function(data) {
                    if(data.errcode != 0)
                    {
                        alert(data.errmsg);

                        resetCaptchaBtn();
                    } else { //  发送成功

                        timeCount();
                    }
                });
                $(self).removeClass("send-standby");
            }

        });

        function resetCaptchaBtn() {
            clearInterval(iTimer);
            $('#send-captcha').text('发送验证码');
            $('#send-captcha').addClass("send-standby");
        }

        //定时器
        function timeCount() {
            var i = 60;
            iTimer = setInterval(function() {
                i <= 0 ? clearInterval(iTimer) : i--;
                $('#send-captcha').text(i + '秒');
                if (i == 0) {
                    resetCaptchaBtn();
                }
            }, 1000);
        }


        //注册
        $('#submit').on("click",function() {

            var mobile = $('#mobile').val();
            var password1 = $('#password1').val();
            var password2 = $('#password2').val();
            var captcha = $('#captcha').val();
            var pattern = /^1[34578]\d{9}$/;
            if (!pattern.test(mobile)) {
                alert("请填写11位数字的正确号码");
                return;
            }
            if (password1 == "" || password2 == "" ||captcha == "") {
                alert("请填写密码和验证码");
                return;
            }

            if(password1.length<6 || password1.length>12){
                alert("请输入6-12位密码");
                return;
            }

            if (password1 != password2) {
                alert("密码不一致");
                return;
            }

            $.post("<?php echo $base_url; ?>/home/account/add", {
                'mobile': mobile,
                'password': password1,
                'captcha': captcha
            }, function(json) {
                var json = eval(json);

                if (json.result == 0) {

                    //帮助登录
                    $.post("<?php echo $base_url; ?>home/account/checkLogin", {
                        'mobile': mobile,
                        'password': password1
                    }, function(json) {
                        if (json.result == 0) {
                            <?php if(empty($back_url)): ?>
                            window.location.href = "<?php echo $base_url; ?>home";
                            <?php else: //跳转到上一个页面?>
                            window.location.href = decodeURIComponent("<?php echo urlencode($back_url); ?>");
                            <?php endif; ?>
                            return;
                        }
                        return;
                    }, 'json');

                } else {
                    alert(json.message);
                    return;
                }

            }, 'json');
        });
    })




</script>

</body>

</html>